#!/bin/bash
## This file is part of the aMule Project
##
## Copyright (c) 2004-2011 Angel Vidal ( kry@amule.org )
## Copyright (c) 2003-2011 aMule Team  ( admin@amule.org / http://www.amule.org )
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either
## version 2 of the License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA

# Wikifies lastest changelog entry. No sanity checking. Must be run from sources root folder.
if test x"`ls docs/Changelog`" = x""; then
  echo "This script must be run on aMule base directory."
else
  CHANGELOG="Changelog-`grep -h -E 'Version [0-9]\.[0-9]+\.[0-9]+.*' docs/Changelog | head -n 1 | cut -d ' ' -f 2`"
  head -n `grep -hn -E '(\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-)+' docs/Changelog | cut -d ':' -f 1 | head -1` docs/Changelog > $CHANGELOG
  sed -i -r "s/\t([A-Z,a-z].+):$/'''\1:'''/g" $CHANGELOG
  sed -i -r "s/^(Version .+)$/=== \1 ===/g" $CHANGELOG
  sed -i -r "s/^-----------*$//g" $CHANGELOG
  sed -i -r "s/^([0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?)$/''\1''/g" $CHANGELOG
  sed -i -r "s/\t+(\*? .+)$/\1/g" $CHANGELOG
  sed -i -r ":0;N;s/\n\s+/ /;t0;P;D" $CHANGELOG
  echo "$CHANGELOG created."
fi
